// pages/staff_manager_edit/staff_manager_edit.js
const config = require('../../config.js');
const utils = require('../../utils/util.js');
const request = require('../../utils/request.js')
import { getStaffDetail, quitStaffAct, setStaffPermission } from '../../static/api/api.js'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id:'',
        isShowDetail:false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options)
        this.setData({
            id:options.id
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getStaffDetail()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },
    showEcode(){
        this.setData({
            isShowDetail: true
        }) 
    },
    hideEcode(){
        this.setData({
            isShowDetail:false
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    getStaffDetail() {
        let that = this;
        wx.showLoading({
            title: '加载中...',
        })
        getStaffDetail({ store_user_id:this.data.id}).then(response => {
            wx.hideLoading();
            console.log(response)
            that.setData({
                'mainData': response.data,
            })
        }).catch(response => {
            wx.hideLoading()
        })

    },
    staffQuit(){
        let that = this;
        wx.showModal({
            title: '温馨提示',
            content: '您确定要离职当前手艺人吗？',
            success: function (res) {
                if (res.confirm) {
                    wx.showLoading({
                        title: '操作中...',
                    })
                    quitStaffAct({ store_user_id: that.data.id,status:'-1' }).then(response => {
                        wx.hideLoading();
                        console.log(response)
                        wx.showToast({
                            icon:'none',
                            title: '操作成功',
                        })
                        setTimeout(function(){
                            wx.navigateBack({
                                
                            })
                        },500)
                        
                    }).catch(response => {
                        wx.hideLoading()
                    })
                    
                } else if (res.cancel) {

                }

            }
        })
    },
    setStaffPermission() {
        let that = this;
        let options = {
            store_user_id: this.data.id,
            is_manager_permission: this.data.mainData.is_manage_permission == 1 ? '0' : '1'
        }
        wx.showLoading({
            title: '加载中...',
        })
        
        setStaffPermission(options).then(response => {
            wx.hideLoading();
            this.setData({
                'mainData.is_manager_permission': this.data.mainData.is_manager_permission == 1 ? '0' : '1'
            })
            wx.showToast({
                icon:'none',
                title: '设置成功',
            })
        }).catch(response => {
            wx.hideLoading()
        })

    },
    changeStaffPermission(){
        let that = this;
        
        wx.showModal({
            title: '温馨提示',
            content: '确定要修改该用户店铺权限吗？',
            success: function (res) {
                if (res.confirm) {
                    that.setStaffPermission()

                } else if (res.cancel) {

                }

            }
        })
    }
})